//
//  BGEntrustDetailController.m
//  bigMall
//
//  Created by ios on 16/9/22.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGEntrustDetailController.h"
#import "BGDateResult.h"
#import "BGGetImageInfoModel.h"
#import "UIImageView+WebCache.h"
#import "BGBasicUrl.h"

@interface BGEntrustDetailController () <UIScrollViewDelegate> {
    
    UIScrollView *_scrollView;
    UIImageView *v1;
    UIImageView *v2;
    UIImageView *v3;
    
}

@end

@implementation BGEntrustDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"委托详情";
    // Do any additional setup after loading the view.
    [self createUI];
    [self loadInter];
    
}
- (void)loadInter {
    
    [BGDateResult getImageInfoWithIds:self.imagUrl success:^(NSObject *result) {
        
        BGGetImageInfoModel *model = (BGGetImageInfoModel *)result;
        
        NSArray *arr = model.res;
        
        for (int i = 0; i < arr.count; i++) {
            
            BGGetImageInfoModelRes *a = arr[i];
            
            if (i == 0) {
                [v1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],a.url]]];
            } else if (i == 1) {
                [v2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],a.url]]];
            } else if (i == 3) {
                [v3 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],a.url]]];
            }
            
        }
        
        
    } failure:^(NSError *error) {
        
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)createUI {
    
    //滚动的视图
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.delegate = self;
    _scrollView.contentSize = CGSizeMake(BGWidth, BGHight + 100);
    _scrollView.backgroundColor = [UIColor whiteColor];
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    UIView *xiushi = [[UIView alloc] initWithFrame:CGRectMake(21, 144 - 64, BGWidth - 42, 1)];
    xiushi.backgroundColor = dockwhite_;
    [_scrollView addSubview:xiushi];
    
    //标题啊
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(21, 84 - 64, 77, 21)];
    title.font = [UIFont systemFontOfSize:16];
    title.text = [NSString stringWithFormat:@"标题：%@",self.title1];
    CGSize labSize = [title.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:title.font,NSFontAttributeName, nil]];
    title.width = labSize.width;
    title.height = labSize.height;
    [_scrollView addSubview:title];
    
    //发件人
    UILabel *person = [[UILabel alloc] initWithFrame:CGRectMake(21, title.bottom + 10, 77, 16)];
    person.font = [UIFont systemFontOfSize:12];
    person.text = [NSString stringWithFormat:@"电话：%@",self.fromname];
    person.textColor = dockGray_;
    CGSize personSize = [person.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:person.font,NSFontAttributeName, nil]];
    person.width = personSize.width;
    person.height = personSize.height;
    [_scrollView addSubview:person];
    
    //小时间
    UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(person.right + 30, title.bottom + 10, BGWidth - person.right + 50 - 21, 16)];
    time.font = [UIFont systemFontOfSize:12];
    NSDate *dat = [NSDate dateWithTimeIntervalSince1970:[self.add_time intValue]];
    NSDateFormatter *fat = [[NSDateFormatter alloc] init];
    [fat setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr = [fat stringFromDate:dat];
    time.text = [NSString stringWithFormat:@"时间：%@",timeStr];
    time.textColor = dockGray_;
    CGSize timeSize = [time.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:time.font,NSFontAttributeName, nil]];
    time.width = timeSize.width;
    time.height = timeSize.height;
    time.textAlignment = NSTextAlignmentRight;
    [_scrollView addSubview:time];
    
    //小详情
    UILabel *detail = [[UILabel alloc] initWithFrame:CGRectMake(21, xiushi.bottom + 10, BGWidth - 42, 100)];
    detail.text = [NSString stringWithFormat:@"详情：%@",self.cont];
    detail.font = [UIFont systemFontOfSize:16];
    detail.numberOfLines = 0;
//    [detail sizeToFit];
    detail.y = xiushi.bottom + 10;
    CGSize detailSize = [detail.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:detail.font,NSFontAttributeName, nil]];
//    //    detail.width = detailSize.width;
//    //    detail.contentInsets = UIEdgeInsetsMake(30, 0, 0, 0);
//    //    if (detailSize.width > BGWidth - 42) {
//    //        detail.height = 21 * detailSize.width / BGWidth - 42 + 1;
//    //    }
    detail.height = detailSize.height;
    [detail sizeToFit];
//    detail.y = xiushi.bottom + 10;
//    detail.numberOfLines = 0;
//    detail.lineBreakMode = NSLineBreakByWordWrapping;
    detail.textAlignment = NSTextAlignmentNatural;
    [_scrollView addSubview:detail];
    
    //小图片
    v1 = [[UIImageView alloc] initWithFrame:CGRectMake(21, detail.bottom + 10, BGWidth - 42, BGHight / 4.1)];
    v1.contentMode = UIViewContentModeScaleToFill;
    [_scrollView addSubview:v1];
    _scrollView.contentSize = CGSizeMake(BGWidth, v1.bottom + 10);
    
//    v2 = [[UIImageView alloc] initWithFrame:CGRectMake(21, v1.bottom + 10, BGWidth - 42, BGHight / 4.1)];
//    v2.contentMode = UIViewContentModeScaleToFill;
//    [_scrollView addSubview:v2];
//    
//    v3 = [[UIImageView alloc] initWithFrame:CGRectMake(21, v2.bottom + 10, BGWidth - 42, BGHight / 4.1)];
//    v3.contentMode = UIViewContentModeScaleToFill;
//    [_scrollView addSubview:v3];
    
    
}
- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
